<%
var headerPart = {
%>
<% include("/include/treetable.html"){} %>
<script type="text/javascript">
    $(document).ready(function() {
        $("#treeTable").treeTable({expandLevel : 3});
    });
    function updateSort() {
        layer.load();
        $("#listForm").attr("action", "${ctx}/cms/category/updateSort");
        $("#listForm").submit();
    }

    function page(n,s){
        $("#pageNo").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }
</script>
<% }; %>
<% layout("/layouts/micro.html",{headerSection:headerPart}){ %>
<div class="layui-fluid">
	<div class="layui-card">
<!--<div class="layui-tab layui-tab-brief childrenBody">
	<ul class="layui-tab-title">
		<li class="layui-this"><a href="${ctx}/cms/category/">栏目列表</a></li>
		<%if(shiro.hasPermission("cms:category:edit")){%><li><a href="${ctx}/cms/category/form">栏目添加</a></li><%}%>
	</ul>-->
		<#message content="${message!}"/>
		<form id="listForm" method="post" class="layui-form">
			<div class="layui-card-body">
				<#message content="${message!}"/>
				<%if(shiro.hasPermission("cms:category:edit")){%>
				<div>
					<a class="layui-btn layui-btn-normal LAY_ADD_category_btn"><i class="layui-icon layui-icon-add-1"></i>添加栏目</a>
					<input id="btnSubmit" class="layui-btn" type="button" value="保存排序" onclick="updateSort();"/>
				</div>
				<%}%>
				<table id="treeTable" class="layui-table" >
					<tr>
						<th>栏目名称</th>
						<th style="text-align:center">栏目编号</th>
						<th style="text-align:center">归属机构</th>
						<th style="text-align:center">栏目模型</th>
						<th style="text-align:center;">排序</th>
						<th style="text-align:center" title="是否在导航中显示该栏目">导航菜单</th>
						<th style="text-align:center" title="是否在分类页中显示该栏目的文章列表">栏目列表</th>
						<th style="text-align:center">展现方式</th>
						<th style="text-align:center;width: 250px;">操作</th>
					</tr>
					<%for(tpl in list){%>
						<tr id="${tpl.id}" pId="${tpl.parent.id != '1'?tpl.parent.id:'0'}">
							<td ><a href="${ctx}/cms/category/form?id=${tpl.id}">${tpl.name}</a></td>
							<td style="text-align:center">${tpl.id}</td>
							<td style="text-align:center">${tpl.office.name}</td>
							<td style="text-align:center">${@DictUtils.getDictLabel(tpl.module, 'cms_module', '公共模型')}</td>
							<td style="text-align:center;">
								<%if(shiro.hasPermission("cms:category:edit")){%>
									<input type="hidden" name="ids" value="${tpl.id}"/>
									<input name="sorts" type="text" value="${tpl.sort}" class="layui-input" style="width:80px;height:22px;margin:0;padding:0;text-align:center;">
								<%}%><%if(shiro.lacksPermission("cms:category:edit")){%>
									${tpl.sort}
								<%}%>
							</td>
							<td style="text-align:center">${@DictUtils.getDictLabel(tpl.inMenu, 'show_hide', '隐藏')}</td>
							<td style="text-align:center">${@DictUtils.getDictLabel(tpl.inList, 'show_hide', '隐藏')}</td>
							<td style="text-align:center">${@DictUtils.getDictLabel(tpl.showModes, 'cms_show_modes', '默认展现方式')}</td>
							<td style="text-align:center">
								<a class="layui-btn layui-btn-xs" href="${ctxFront}/list-${tpl.id}${@Global.getUrlSuffix()}" target="_blank">访问</a>
								<%if(shiro.hasPermission("cms:category:edit")){%>
									<a class="layui-btn layui-btn-xs" onclick="editCategory('${tpl.id}')" href="javascript:void(0);">修改</a>
									<a class="layui-btn layui-btn-xs" onclick="addNextCategory('${tpl.id}')" href="javascript:void(0);">添加下级栏目</a>
									<a class="layui-btn layui-btn-xs layui-btn-danger" href="${ctx}/cms/category/delete?id=${tpl.id}" onclick="return confirmx('要删除该栏目及所有子栏目项吗？', this.href)">删除</a>
								<%}%>
							</td>
						</tr>
					<%}elsefor{%>
						<tr><td colspan="9" align="center">暂无数据</td></tr>
					<%}%>
				</table>
			</div>
		</form>
	</div>
</div>
<script>
    layui.use(['form','layer'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
        //添加
        $(".LAY_ADD_category_btn").click(function(){
            var index = layui.layer.open({
                title : "添加栏目",
                type : 2,
                content : "${ctx}/cms/category/form",
                maxmin: true,
                area: ['100%', '100%'],
                btn: ['确定', '取消'],
                yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find('#categoryForm');
                    submit.trigger('click');
                    layer.close(index);
                },
                end:function(){
                    location.reload();
                }
            })
        })
    })
    var editCategory = function(id){
        var index = layui.layer.open({
            title : "修改栏目",
            type : 2,
            content : "${ctx}/cms/category/form?id="+id,
            maxmin: true,
            area: ['100%', '100%'],
            btn: ['确定', '取消'],
            yes: function(index, layero){
                var submit = layero.find('iframe').contents().find('#categoryForm');
                submit.trigger('click');
                layer.close(index);
            },
			end:function(){
                location.reload();
			}
        })
    }
    var addNextCategory = function(id){
        var index = layui.layer.open({
            title : "添加下级栏目",
            type : 2,
            content : "${ctx}/cms/category/form?parent.id="+id,
            maxmin: true,
            area: ['100%', '100%'],
            btn: ['确定', '取消'],
            yes: function(index, layero){
                var submit = layero.find('iframe').contents().find('#categoryForm');
                submit.trigger('click');
                window.location.reload();
                layer.close(index);
            },
            end:function(){
                location.reload();
            }
        })
    }
</script>
<%}%>